<%--
  Created by IntelliJ IDEA.
  User: 王志斌
  Date: 2019/2/13
  Time: 11:47
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
    String path = request.getContextPath();

%>
<html>
<head>
    <title>首页</title>
    <meta charset="UTF-8">
    <script type="text/javascript" src="<%=path%>/static/jquery-3.2.1.js"></script>
</head>
<body>
<div>
    <div>
        <input type="text" id="inputText">
        <select id="typeSelect">
            <option value="111">请选择</option>
            <c:forEach items="${requestScope.productTypes}" var="list">
                <option value="${list.id}">${list.title}</option>
            </c:forEach>
        </select>

        <select id="reSelect">
            <option value="111">请选择</option>
            <option value="1">热门</option>
            <option value="10">非热门</option>
        </select>
        <button id="button">
            搜索
        </button>
    </div>

    <table>
        <thead>
        <tr>
            <th>标题</th>
            <th>类型</th>
            <th>价格</th>
            <th>是否热门</th>
            <th>时间</th>
            <th>浏览次数</th>
        </thead>
        <tbody>
            <c:forEach items="${requestScope.products}" var="list">
                <tr>
                    <td>${list.title}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
                    <td>${list.productType.title}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
                    <td>${list.price}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>

                    <c:if test="${list.isHot eq 1}">
                        <td>热门&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
                    </c:if>

                    <c:if test="${list.isHot eq 0}">
                        <td>非热门&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
                    </c:if>

                    <td><fmt:formatDate value="${list.inputTime}" pattern="yyyy-MM-dd"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
                    <td>${list.viewCount}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
                </tr>
            </c:forEach>
        </tbody>
    </table>




    <div>
        <div>
            <c:forEach begin="1" end="${requestScope.pager.pageCount}" varStatus="i">
                <a href="<%=path%>/index?pageNo=${i.count}<c:if test="${!empty param['title']}">&title=${param['title']}</c:if><c:if test="${!empty param['productType.id']}">&productType.id=${param['productType.id']}</c:if><c:if test="${!empty param['isHot']}">&isHot=${param['isHot']}</c:if>">${i.count}</a>
            </c:forEach>
        </div>
    </div>

</div>
</body>


<script>
    $(function () {


        $("#button").click(function () {
            var inputText = $("#inputText").val();
            var typeSelect = $("#typeSelect").val();
            var reSelect = $("#reSelect").val();

            window.location.href="<%=path%>/index?title="+inputText+"&productType.id="+typeSelect+"&isHot="+reSelect;



        });
        

        
        
        
        
    });
</script>


</html>
